﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ATM_Client.Properties;

namespace ATM_Client
{
    public partial class Withdraw : Form
    {
        public static string token = "";
        readonly IATM _client = new ATMClient();
        
        public Withdraw()
        {
            InitializeComponent();
        }

        private void BtnOkClick(object sender, EventArgs e)
        {
            int validateValue = Convert.ToInt32(txtInput.Text);
            if((validateValue%20)==0)
            {
                int isSuccess = _client.Withdraw(token, Convert.ToInt64(txtInput.Text));
                if (isSuccess == 0)
                {
                    MessageBox.Show(Resources.Withdraw_btnOK_Click_Withdraw_Successfully__Please_check_the_money_);
                    ViewBalance.token = token;
                    var form = new ViewBalance();
                    form.Show();
                    this.Dispose();
                }
                else
                {
                    MessageBox.Show(_client.GetError(isSuccess));
                }
            }
            else
            {
                MessageBox.Show("The money you wat to withdraw must be mutiple of 20");
            }
        }
        

        private void BtnBackClick(object sender, EventArgs e)
        {
            MainForm.token = token;
            var form = new MainForm();
            form.Show();
            this.Dispose();
        }

        private void WithdrawLoad(object sender, EventArgs e)
        {
            lblcash.Text = _client.ShowBalance(token);
        }
    }
}
